package com.tianshi.pxx.mapper;


import com.tianshi.pxx.pojo.entity.Orders;
import com.tianshi.pxx.pojo.entity.Product;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface OrdersMapper {

    /*
    * 先查询商品订单,在通过商品查询商品信息
    * */
    @Select("select * from product where id in (select product_id from orders where user_id=#{id})")
    List<Product> list(Integer id);

    @Select("select * from product where name like concat('%',#{productName},'%') " +
            "and id in (select product_id from orders where user_id=#{id})")
    List<Product> searchByName(@Param("productName") String productName, @Param("id") Integer id);

    @Delete("delete from orders where product_id=#{id}")
    Integer deleteById(Integer id);

    void insertOrdersList(@Param("ordersList") List<Orders> ordersList);
}
